﻿using System;
using System.Collections.Generic;
using System.Data;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using MakeItWeb.Framework;

namespace AllNations.WebAppAdmin
{
    public partial class Announcement : MakeItWebAdminPage
    {
        protected void Page_Load(object sender, EventArgs e)
        {
            if (!IsPostBack)
            {
                using (DataSet ds = GenericQry.GetDataSet("proc_cm_GetQuickAnnouncement", new StoredProcArgs()))
                {
                    if (ds.Tables[0].Rows.Count == 1)
                    {
                        DataRow dr = ds.Tables[0].Rows[0];

                        txtAnnouncement.Text = dr["quick_announcement_txt"].ToString();
                        if (!dr.IsNull("effective_date_from"))
                            EffectiveDateFrom.SelectedDate = (DateTime) dr["effective_date_from"];
                        if (!dr.IsNull("effective_date_to"))
                            EffectiveDateTo.SelectedDate = (DateTime) dr["effective_date_to"];
                        cbEnabled.Checked = (bool) dr["enabled_ind"];
                    }
                }
            }
        }

        protected void btSave_OnClick(object sender, EventArgs e)
        {
            var args = new StoredProcArgs();
            args["pQuickAnnouncementTxt"] = txtAnnouncement.Text.Trim();
            if (EffectiveDateFrom.SelectedDate.HasValue)
                args["pEffectiveDateFrom"] = EffectiveDateFrom.SelectedDate.Value;
            if (EffectiveDateTo.SelectedDate.HasValue)
                args["pEffectiveDateTo"] = EffectiveDateTo.SelectedDate.Value;
            args["pEnabledInd"] = cbEnabled.Checked;

            GenericCud.ExecuteCud("proc_cm_SaveQuickAnnouncement", args);
        }
    }
}